#ifndef QFFPLAYER_H
#define QFFPLAYER_H

#include <QObject>
#include <QImage>
#include <QThread>
extern "C" {
    #include "ffplay.h"
}

class PlayerThread : public QThread
{
    Q_OBJECT
public:
    PlayerThread() {

    }
    void setDisplayFile(QString filename) {
        show_file_name = filename;
    }

    void run();

    void setVideoState(VideoState *is);

signals:
    void playStop(int state);
    void playStart(int state);
private:
    QString show_file_name;
    VideoState * video_state;
};

class QFfplayer : public QObject
{
    Q_OBJECT
public:
    explicit QFfplayer(QObject *parent = nullptr);
    virtual ~QFfplayer();
    void setWinID(void* winID);
    void setDisplayFile(const QString& filename);
    const QImage& getCurrentImage();
signals:
    void sendPicture(const char *pData, size_t s);
    void sendVoice(const char *pData, size_t s);
public slots:
    void updateState(int state) {
        m_currentState = state;
    }
    int playVideo(const QString& filename);
    int stopVideo();
    int pauseVideo();
    int resumeVideo();
    int updateVolume(int sign, double step);
    int muteAudio();
    int changeShowMode();
    int setSubtitleFile(const QString& filename);
    double updateSpeed(double val, int relative);
    int stream_seek_safe(double incr, int seek_by_bytes);
private:
    VideoState *m_pVideoState;
    QString m_showFileName;
    QString m_proName;
    QImage m_currentImage;
    int m_pauseState;
    volatile int m_currentState;
    PlayerThread *m_pPlayThd;
    QString m_subtitileFileName;
    void * m_render_wnd;
};

#endif // QFFPLAYER_H
